#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>

using namespace std;

// 904. 水果成篮
// https://leetcode.cn/problems/fruit-into-baskets/description/

class Solution {
public:
    int totalFruit(vector<int>& fruits) {
        unordered_map<int, int> recordKind;
        int n = fruits.size();
        int left = 0;
        int ans = 0;
        for (int i = 0; i < n; i++)
        {
            int curKind = fruits[i];
            recordKind[curKind]++;
            while(recordKind.size() > 2){
                recordKind[fruits[left]]--;
                if(recordKind[fruits[left]] == 0){
                    recordKind.erase(fruits[left]);
                }
                left++;
            }
            ans = max(ans, i - left + 1);
        }
        return ans;
    }
};

int main()
{
    return 0;
}